# -*- encoding:utf-8 -*-
"""
@作者：jiajun_Tang
@文件名：get_image.py
@时间：2023/3/28  下午 03:32
@文档说明:
"""
import cv2
import sys
import config
import numpy as np
from time import time
from pathlib import Path

# 获取当前py文件所在目录
# root_path = Path.cwd()
# file_path = root_path.joinpath('config.yaml')

# with open(file_path, 'r', encoding='utf-8') as f:
#     print(file_path)
#     config_dict = yaml.load(f, Loader=yaml.SafeLoader)  # data dict
#     SCALE_X = config_dict.get('horizontal_pixel') / config_dict.get('horizontal_graphics')  # 水平方向放缩比例
#     SCALE_Y = config_dict.get('vertical_pixel') / config_dict.get('vertical_graphics')  # 垂直方向放缩比例
#     detection_accuracy = config_dict.get('detection_accuracy')


# detection_accuracy = config.detection_accuracy

'''
数据结构
display_item: 
    {
       "glass_id": count, # 玻璃计数编号
       "start_time": start_time, # 开始时间
       "pname": pname, # 工位名称
       "defect_list": # 瑕疵列表
           [
               {"img": source[left_y: left_y+height, left_x: left_x+width],
                "accuracy": float(conf * 100), "event_type": str(names[int(cls)]),
                "left_x": left_x + l_x, "left_y": left_y + l_y,
                "width": width, "height": height   # 单位：像素
                "attribute": {"length": length, "wide": wide, "cal": cal}  # 单位：像素
                }
           ]
       "cir_mat": cir_mat, # 瑕疵间距矩阵
       "pic": pic, # 单个工位整张大图
       "glass":  # 大图玻璃坐标
           [
               {"img": source[left_y: left_y+height, left_x: left_x+width],
                "accuracy": float(conf * 100), "event_type": str(names[int(cls)]),
                "left_x": left_x + l_x, "left_y": left_y + l_y,
                "width": width, "height": height  # 单位：像素
                }
           ]
    }
'''
#
# def get_detection_result():
#     """ 获取检测的结果"""
#     point_list = [(30, 30, 18), (69, 85, 20), (166, 188, 32), (677, 680, 36), (250, 300, 20)]
#
#     img1 = cv2.imread(r'./img/1_7_102_6164_16_13_air_bubbles.jpg')
#     img2 = cv2.imread(r'./img/1_10_791_9657_19_131_scratches.jpg')
#
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 1,  # 第几片玻璃
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'coax',  # 检测工位标识
#         "defect_list": [{  # 瑕疵列表
#             "img": img1,
#             "accuracy": 58.39617919921875,
#             "event_type": "scratch",
#             "left_x": 5244, "left_y": 5893,
#             "width": 300, "height": 600,
#             "attribute": {
#                 "length": 200, "wide": 500, 'cal': 100  # 长 宽 直径
#             }
#         },
#             {
#                 "img": img2,
#                 "accuracy": 63.859291076660156,
#                 "event_type": "scratch",
#                 "left_x": 7081, "left_y": 1952,
#                 "width": 370, "height": 160,
#                 "attribute": {
#                     "length": 10,
#                     "wide": 50,
#                     'cal': 60
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }]
#     }
#
#     glass_id = display_item['glass_id']  # 当前玻璃所属的片数
#
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  # 添加至数组中
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_cal = item['attribute']['wide'] * detection_accuracy**2  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_cal))
#
#     return point_attributes
#
#
# def get_detection_result1():
#     """ 获取检测的结果"""
#
#     img1 = cv2.imread(r'./img/1_7_102_6164_16_13_air_bubbles.jpg')
#     img2 = cv2.imread(r'./img/1_10_791_9657_19_131_scratches.jpg')
#
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 1,    # 第几片玻璃
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'coax',  # 检测工位标识
#         "defect_list": [{  # 瑕疵列表
#             "img": img1,
#             "accuracy": 58.39617919921875,
#             "event_type": "flakes",
#             "left_x": 6164, "left_y": 1002,
#             "width": 150, "height": 150,
#             "attribute": {
#                 "length": 100,
#                 "wide": 50,
#                 'cal': 100
#             }
#         },
#             {
#                 "img": img2,
#                 "accuracy": 63.859291076660156,
#                 "event_type": "flakes",
#                 "left_x": 8081, "left_y": 1952,
#                 "width": 370, "height": 160,
#                 "attribute": {
#                     "length": 55,
#                     "wide": 95,
#                     'cal': 64
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }]
#     }
#     glass_id = display_item['glass_id']  # 当前玻璃所属的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  # 添加至数组中
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_cal = item['attribute']['wide'] * detection_accuracy**2  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_cal))
#
#     return point_attributes
#
#
# def get_detection_result2():
#     """ 获取检测的结果"""
#
#     img3 = cv2.imread(r'./img/1_10_799_6380_18_19_air_bubbles.jpg')
#     img5 = cv2.imread(r'./img/1_10_960_8510_63_77_scratches.jpg')
#
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 2,  # 第几片玻璃2, 11, 20230411_171459_062867, 1280, 65536
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'back',  # 检测工位标识
#         "defect_list": [{  # 瑕疵列表
#             "img": img3,
#             "accuracy": 58.39617919921875,
#             "event_type": "gum_injury",
#             "left_x": 16380, "left_y": 15199,
#             "width": 150, "height": 150,
#             "attribute": {
#                 "length": 20,
#                 "wide": 50,
#                 "cal": 60
#             }
#         },
#             {
#                 "img": img5,
#                 "accuracy": 63.859291076660156,
#                 "event_type": "gum_injury",
#                 "left_x": 10081, "left_y": 5652,
#                 "width": 370, "height": 160,
#                 "attribute": {
#                     "length": 65,
#                     "wide": 95,
#                     "cal": 100
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }
#         ]
#     }
#
#     glass_id = display_item['glass_id']  # 当前玻璃的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  # 添加至数组中
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_cal = item['attribute']['cal']  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_cal))
#
#     return point_attributes
#
#
# def get_detection_result3():
#     """ 获取检测的结果"""
#
#     img7 = cv2.imread(r'./img/1_11_607_9184_99_54_stain.jpg')
#     img10 = cv2.imread(r'./img/1_12_253_9147_26_30_air_bubbles.jpg')
#     img14 = cv2.imread(r'./img/1_17_1206_11295_54_25_stain.jpg')
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 3,  # 第几片玻璃2, 11, 20230411_171459_062867, 1280, 65536
#         "glass_sub_id": 18,  # 当前玻璃的分块数(垂直方向切分)
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "defect_list": [{  # 瑕疵列表
#             "img": img10,
#             "accuracy": 81.39617919921875,
#             "event_type": "air_bubbles",
#             "left_x": 6164, "left_y": 102,
#             "width": 260, "height": 300,
#             "attribute": {
#                 "length": 10,
#                 "wide": 8,
#                 "cal": 10
#             }
#         },
#             {
#                 "img": img7,
#                 "accuracy": 71.859291076660156,
#                 "event_type": "stain",
#                 "left_x": 9184, "left_y": 607,
#                 "width": 370, "height": 160,
#                 "attribute": {
#                     "length": 53,
#                     "wide": 24,
#                     "cal": 65
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }]
#     }
#
#     glass_id = display_item['glass_id']  # 当前玻璃的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  # 添加至数组中
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_cal = item['attribute']['cal']  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_cal))
#
#     return point_attributes
#
#
# def get_detection_result4():
#     """ 获取检测的结果"""
#     point_list = [(30, 30, 18), (69, 85, 20), (166, 188, 32), (677, 680, 36), (250, 300, 20)]
#
#     img1 = cv2.imread(r'./img/1_7_102_6164_16_13_air_bubbles.jpg')
#     img2 = cv2.imread(r'./img/1_10_791_9657_19_131_scratches.jpg')
#
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 4,  # 第几片玻璃2, 11, 20230411_171459_062867, 1280, 65536
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'coax',  # 检测工位标识
#         "defect_list": [{  # 瑕疵列表
#             "img": img1,
#             "accuracy": 58.39617919921875,
#             "event_type": "scratch",
#             "left_x": 5244, "left_y": 5893,
#             "width": 150, "height": 150,
#             "attribute": {
#                 "length": 10, "wide": 5, "cal": 10
#             }
#         },
#             {
#                 "img": img2,
#                 "accuracy": 63.859291076660156,
#                 "event_type": "scratch",
#                 "left_x": 7081, "left_y": 1952,
#                 "width": 37, "height": 16,
#                 "attribute": {
#                     "length": 12,
#                     "wide": 8,
#                     "cal": 12
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }]
#     }
#     glass_id = display_item['glass_id']  # 当前玻璃的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  #
#     # pname = display_item['pname']        # 当前检测结果的工位标识
#     # point_attributes.append((pname))  #
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_cal = item['attribute']['cal'] * detection_accuracy**2  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_cal))
#
#     return point_attributes
#
#
# def get_detection_result5():
#     """ 获取检测的结果"""
#
#     img1 = cv2.imread(r'./img/1_7_102_6164_16_13_air_bubbles.jpg')
#     img2 = cv2.imread(r'./img/1_10_791_9657_19_131_scratches.jpg')
#
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 5,  # 第几片玻璃2, 11, 20230411_171459_062867, 1280, 65536
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'coax',  # 检测工位标识
#         "defect_list": [{  # 瑕疵列表
#             "img": img1,
#             "accuracy": 58.39617919921875,
#             "event_type": "flakes",
#             "left_x": 6164, "left_y": 1002,
#             "width": 150, "height": 150,
#             "attribute": {
#                 "length": 10,
#                 "wide": 5,
#                 "cal": 20
#             }
#         },
#             {
#                 "img": img2,
#                 "accuracy": 63.859291076660156,
#                 "event_type": "flakes",
#                 "left_x": 8081, "left_y": 1952,
#                 "width": 370, "height": 160,
#                 "attribute": {
#                     "length": 65,
#                     "wide": 95,
#                     "cal": 20
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }]
#     }
#     glass_id = display_item['glass_id']  # 当前玻璃的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  #
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_cal = item['attribute']['cal'] * detection_accuracy**2  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_cal))
#
#     return point_attributes
#
#
# def get_detection_result6():
#     """ 获取检测的结果"""
#
#     img3 = cv2.imread(r'./img/1_10_799_6380_18_19_air_bubbles.jpg')
#     img5 = cv2.imread(r'./img/1_10_960_8510_63_77_scratches.jpg')
#
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 6,  # 第几片玻璃2, 11, 20230411_171459_062867, 1280, 65536
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'back',  # 检测工位标识
#         "defect_list": [{  # 瑕疵列表
#             "img": img3,
#             "accuracy": 58.39617919921875,
#             "event_type": "gum_injury",
#             "left_x": 16380, "left_y": 15199,
#             "width": 150, "height": 150,
#             "attribute": {
#                 "length": 10,
#                 "wide": 5,
#                 'cal': 10
#             }
#         },
#             {
#                 "img": img5,
#                 "accuracy": 63.859291076660156,
#                 "event_type": "gum_injury",
#                 "left_x": 10081, "left_y": 5652,
#                 "width": 370, "height": 160,
#                 "attribute": {
#                     "length": 55,
#                     "wide": 95,
#                     "cal": 95
#                 }
#             }
#         ],
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }
#         ]
#     }
#
#     glass_id = display_item['glass_id']  # 当前玻璃的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  #
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_diameter = item['attribute']['cal'] * detection_accuracy**2  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_diameter))
#
#     return point_attributes
#
#
# def get_detection_result7():
#     """ 获取检测的结果"""
#
#     img7 = cv2.imread(r'./img/1_11_607_9184_99_54_stain.jpg')
#     img10 = cv2.imread(r'./img/1_12_253_9147_26_30_air_bubbles.jpg')
#     img14 = cv2.imread(r'./img/1_17_1206_11295_54_25_stain.jpg')
#     point_attributes = []
#
#     display_item = {
#         "glass_id": 7,  # 第几片玻璃2, 11, 20230411_171459_062867, 1280, 65536
#         "start_time": 20230411_171459_062867,  # 开始时间
#         "pname": 'back',  # 检测工位标识
#         "defect_list": [],
#
#         "cir_mat": np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]),
#         "pic": "",
#         "glass": [{
#             "img": '',
#             "accuracy": 86.000,
#             "event_type": "bursting_point",
#             "left_x": 2000,
#             "left_y": 3000,
#             "width": 3680,
#             "height": 3200
#         }
#         ]
#     }
#
#     glass_id = display_item['glass_id']  # 当前玻璃的片数
#     pname = display_item['pname']  # 当前检测结果的工位标识
#     point_attributes.append((glass_id, pname))  #
#
#     for item in display_item['defect_list']:
#         window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
#         window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
#         defect_type = item['event_type']  # 瑕疵类型
#         defect_img = item['img']  # 缺陷细节图
#         accuracy = item['accuracy']  # 缺陷种类置信度
#         defect_length = item['height'] * detection_accuracy  # 缺陷的长度
#         defect_wide = item['width'] * detection_accuracy  # 缺陷的宽度
#         defect_diameter = item['attribute']['cal'] * detection_accuracy**2  # 缺陷的直径
#
#         point_attributes.append((window_x, window_y, defect_type, defect_img, accuracy, defect_length, defect_wide, defect_diameter))
#
#     return point_attributes
#

def dis_consumer(display_queue, SCALE_X, SCALE_Y, rate, non_large_suppression=False):
    """ 从队列中获取检测数据

    Args:
        display_queue:队列
        rate: 像素值与窗口显示分辨率的比率
        non_large_suppression: 为True时, 只保留前三个较大值
    Returns:
        display_item:检测结果
    """
    point_attributes = []

    display_item = display_queue.get()
    # print("display consumer glass_id: {}, startTime: {}, pid: {}, defect_list: {}".
    #       format(display_item["start_time"], display_item["glass_id"], display_item["pname"], display_item["defect_list"]))


    # {"glass_id": display_pre_item["glass_id"], "start_time": display_pre_item["start_time"],
    #  "pname": display_pre_item["pid"],
    #  "defect_list": display_pre_item["defect_list"],

    # 解析数据
    glass_id = display_item['glass_id']  # 当前玻璃的片数
    pname = display_item['pname']  # 当前检测结果的工位标识
    point_attributes.append((glass_id, pname))  #

    # 初始化三个最大数据，作为对比
    max1, max2, max3 = 1, 1, 1
    value1, value2, value3 = 1, 1, 1

    for item in display_item['defect_list']:
        window_x = int(item['left_x'] / SCALE_X)  # 转换后X坐标
        window_y = int(item['left_y'] / SCALE_Y)  # 转换后Y坐标
        defect_type = item['event_type']  # 瑕疵类型
        img = item['img']  # 缺陷细节图
        accuracy = item['accuracy']  # 缺陷种类置信度

        defect_length = item['height'] * config.detection_accuracy  # 缺陷的长度
        defect_wide = item['width'] * config.detection_accuracy  # 缺陷的宽度
        # defect_diameter = item['attribute']['cal'] * detection_accuracy**2  # 缺陷的直径

        # 判断是否只展示前三个较大数值
        if non_large_suppression:
            if defect_length > max1:
                # 当大于第一个数时，更新最大数的三个数并将数据存入队列
                max3 = max2
                max2 = max1
                max1 = defect_length
                value1 = (window_x, window_y, defect_type, img, accuracy, defect_length, defect_wide)
            elif defect_length > max2:
                # 当大于第二个数时，更新最大数的两个数并将数据存入队列
                max3 = max2
                max2 = defect_length
                value2 = (window_x, window_y, defect_type, img, accuracy, defect_length, defect_wide)
            elif defect_length > max3:
                # 当大于第三个数时，更新最大数的最后一个数并将数据存入队列
                max3 = defect_length
                value3 = (window_x, window_y, defect_type, img, accuracy, defect_length, defect_wide)
        else:
            point_attributes.append(
                (window_x, window_y, defect_type, img, accuracy, defect_length, defect_wide))

    if non_large_suppression:
        if 1 != value1:
            point_attributes.append(value1)
        elif 1 != value2:
            point_attributes.append(value2)
        elif 1 != value3:
            point_attributes.append(value3)
    # print("GGGGGG", point_attributes)

    return point_attributes
